﻿@model WebApplication1.Models.Movie
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title> @Model.Title</title>
</head>
<body>
    <span style="font-size: 18pt;">Hello, <b>MVC</b> world!</span>
    The movie <b>@Model.Title</b> was released @Model.ReleaseDate.ToLongDateString()
    <br />

    @*HTML Encoding*@
    @{
        var helloWorld = "<b>Hello, world!</b>";
    }
    <p>@helloWorld</p>
    <p>@Html.Raw(helloWorld)</p>
    <br />

    @*Explicit expressions*@
    @{
        var name = "John Doe";
    }
    Hello, @(name.Substring(0, 4)). Your age is: <b>@(37 + 5).</b>

    @*Multi-statement Razor blocks*@
    @{
        var sum = 32 + 10;
        var greeting = "Hello, world!";
        var text = "";
        for (int i = 0; i < 3; i++)
        {
            text += greeting + " The result is: " + sum + "\n";
        }
    }

    @* HTML tags and plain text inside code blocks *@
    @{
        @:This is plain text!
        <br><br>
        <text>zzThis is plain text as well, and we can
            even span multiple lines, if needed!</text>
    }


    @*
        Here's a Razor server-side comment
        It won't be rendered to the browser
        It can span multiple lines
    *@


    @{
        @*
            Here's a Razor server-side comment
        *@
        // C# style single-line comment
        //(If you're inside a Razor code block, you can even use the regular C# style comments)

        /*
        C# style multiline comment
        It can span multiple lines
        */
    }
    <br />
    @{
        string helloWorldMsg = "Hello, world!";
    }

    <div>
        @helloWorldMsg
    </div>

    @{
        string helloWorldMsg1 = "Good day";
        if (DateTime.Now.Hour > 17)
        {
            helloWorldMsg1 = "Good evening";
        }
        helloWorldMsg1 += ", world!";
        helloWorldMsg1 = helloWorldMsg1.ToUpper();
    }

    <div>
        @helloWorldMsg1
    </div>

    @if (DateTime.Now.Year >= 2042 || DateTime.Now.Year == 2020)
    {
        <span>The flying car has finally arrived!</span>
    }
    else
    {
        <span>We're still waiting for the year of 2042...</span>
    }


    @{
        List<string> names = new List<string>()
{
                "John Doe",
                "Jane Doe",
                "Joe Doe",
                "Jenna Doe",
                "Doggy Doe"
            };
    }

    @*For loop*@
    <ul>
        @for (int i = 0; i < names.Count; i++)
        {
            <li>@names[i]</li>
        }
    </ul>
    @*For each loop*@
    <ul>
        @foreach (string namex in names)
        {
            <li>@namex</li>
        }
    </ul>
    @*While loop*@
    <ul>
        @{
            int counter = 0;
        }
        @while (counter < names.Count)
        {
            <li>@names[counter++]</li>
        }
    </ul>
    @*do...while" loop*@
    <ul>
        @{
            counter = 0;
        }
        @do
        {
            <li>@names[counter++]</li>
        } while (counter < names.Count);
    </ul>

    @*break/continue*@
    <ul>
        @for (int i = 0; i < names.Count; i++)
        {
            <li>@names[i]</li>

            @if (i >= 2)
            {
                <li>...and so on</li>

                break;
            }
        }
    </ul>

    @{
        Func<dynamic, object> movieTemplate = @<div>@item.Title [@item.ReleaseDate.ToShortDateString()]</div>; //The Godfather [24/3/1972]

List<Movie> movies = new List<Movie>();
movies.Add(new Movie() { Title = "The Godfather", ReleaseDate = new DateTime(1972, 3, 24) });
movies.Add(new Movie() { Title = "Forrest Gump", ReleaseDate = new DateTime(1994, 7, 6) });
movies.Add(new Movie() { Title = "Fight Club", ReleaseDate = new DateTime(1999, 10, 15) });
    }

    @foreach (var movie in movies)
    {
        @movieTemplate(movie)
    }
</body>
</html>
